package com.gy.smart.handle;

import android.graphics.Bitmap;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.gy.smart.MyApplication;
import com.gy.smart.R;
import com.gy.smart.base.BaseActivity;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;

/**
 * Created by 高岳 on 2017/1/12.
 * Describe:显示图片
 */
public class ShowPicActivity extends BaseActivity {

    private ImageView imgPic;
    private String imgUrl;
    private Bitmap bitmap;

    @Override
    protected void initView() {
        setContentViewRes(R.layout.activity_show_pic);
        imgPic = (ImageView) findViewById(R.id.activity_shop_pic_img);

    }

    @Override
    protected void initData() {
        imgUrl = getIntent().getStringExtra("imgurl");
    }

    @Override
    protected void fillData() {
        super.fillData();
        ImageLoader.getInstance().displayImage(imgUrl,imgPic,
                new DisplayImageOptions.Builder().bitmapConfig(Bitmap.Config.RGB_565).build());
        ImageLoader.getInstance().loadImage(imgUrl, new ImageLoadingListener() {
            @Override
            public void onLoadingStarted(String imageUri, View view) {

            }

            @Override
            public void onLoadingFailed(String imageUri, View view, FailReason failReason) {

            }

            @Override
            public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                bitmap = loadedImage;
                float scale = (float) loadedImage.getHeight() / loadedImage.getWidth();
                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(MyApplication.screenWidth, (int) (MyApplication.screenWidth * scale));
                imgPic.setLayoutParams(params);
                imgPic.setImageBitmap(bitmap);
            }

            @Override
            public void onLoadingCancelled(String imageUri, View view) {

            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        bitmap.recycle();
        System.gc();
    }
}
